package Euler54;

import java.io.*;
import java.util.*;

public class Poker {
	public static void main(String[] args) {
		int p1wins = 0, p2wins = 0;
		Hand p1, p2;
		
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("poker.txt"));
			String line;
			while ((line = br.readLine()) != null) {
				String tokens[] = line.split(" ");
				String arr1[] = new String[5], arr2[] = new String[5];
				
				for(int i = 0; i < 10; i++)
				{
					if(i<5)
					{
						arr1[i] = tokens[i];
					}
					else
					{
						arr2[i-5] = tokens[i];
					}
				}
				p1 = new Hand(arr1);
				p2 = new Hand(arr2);
				
				int cmp = p1.compareTo(p2);
				if(cmp>0)
				{
					p1wins++;
					System.out.println("Player 1 Hand: " + p1 + "   " + p1.getHandRank());
					System.out.println("Player 2 Hand: " + p2 + "   " + p2.getHandRank());
					System.out.println();
				}
				else if(cmp<0) 
				{
					p2wins++;
				}
			}
			br.close();
			
		}
		catch(Exception e)
		{
			System.out.println("Error!");
		}
		
		System.out.println("p1 won " + p1wins + " times...");
	}
}
